﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using Microsoft.Practices.CompositeWeb;
using NetDon.OA.Interface.Common;
using NetDon.Utilities;

namespace NetDon.OA.Portal.Admin
{
    public class RouteInfoEditPresenter : Presenter<IRouteInfoEditView>
    {
        public override void OnViewInitialized()
        {
            var service = ServiceContainer.GetService<IRouteInfoService>();
            var entity = service.GetRouteById(View.RouteId);
            View.PopulateRouteData(entity);
        }

        public override void OnViewLoaded()
        {
            View.SaveRouteData+=new EventHandler(View_SaveRouteData);
        }

        void View_SaveRouteData(object sender, EventArgs e)
        {
       
            var service = ServiceContainer.GetService<IRouteInfoService>();
            var data = new RouteData() { Id = View.RouteId };
            View.ExtractRouteData(data);
            bool result;
            if (View.RouteId == Guid.Empty)
            {
                result = service.AddRoute(data);
            }
            else
            {
                result = service.ModifyRoute(data);
            }
            if (result)
            {
                View.CloseWindow(true);
            }

        }
    }
}
